prune: Don't fail on partial commits
authorDan Nicholson <nicholson@endlessm.com>
Wed, 23 Mar 2016 16:47:51 +0000 (09:47 -0700)
committerColin Walters <walters@verbum.org>
Wed, 23 Mar 2016 19:34:17 +0000 (15:34 -0400)
If a commit only pull has been done, then the commit object exists in
the object store in addition to the commitpartial file. Traversing this
partial commit will likely fail, but that's expected. If traverse
returns a G_IO_ERROR_NOT_FOUND in this case, continue with pruning.

https://bugzilla.gnome.org/show_bug.cgi?id=764091

src/libostree/ostree-repo-prune.c

index 2d93a9cb08f828d39b0d7fd2eeb34e8836425206..eca2cff683ee7e20f246e81c5b5debc546ba47cf 100644 (file)
@@ -303,10 +303,28 @@ ostree_repo_prune (OstreeRepo        *self,
       while (g_hash_table_iter_next (&hash_iter, &key, &value))
         {
           const char *checksum = value;
-          
-          if (!ostree_repo_traverse_commit_union (self, checksum, depth, data.reachable,
-                                            cancellable, error))
+          OstreeRepoCommitState commitstate;
+          GError *local_error = NULL;
+
+          if (!ostree_repo_load_commit (self, checksum, NULL, &commitstate,
+                                        error))
             goto out;
+
+          if (!ostree_repo_traverse_commit_union (self, checksum, depth, data.reachable,
+                                                  cancellable, &local_error))
+            {
+              /* Don't fail traversing a partial commit */
+              if ((commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) > 0 &&
+                  g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+                {
+                  g_clear_error (&local_error);
+                }
+              else
+                {
+                  g_propagate_error (error, local_error);
+                  goto out;
+                }
+            }
         }
     }
 
@@ -322,15 +340,33 @@ ostree_repo_prune (OstreeRepo        *self,
           GVariant *serialized_key = key;
           const char *checksum;
           OstreeObjectType objtype;
+          OstreeRepoCommitState commitstate;
+          GError *local_error = NULL;
 
           ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
 
           if (objtype != OSTREE_OBJECT_TYPE_COMMIT)
             continue;
-          
-          if (!ostree_repo_traverse_commit_union (self, checksum, depth, data.reachable,
-                                                  cancellable, error))
+
+          if (!ostree_repo_load_commit (self, checksum, NULL, &commitstate,
+                                        error))
             goto out;
+
+          if (!ostree_repo_traverse_commit_union (self, checksum, depth, data.reachable,
+                                                  cancellable, &local_error))
+            {
+              /* Don't fail traversing a partial commit */
+              if ((commitstate & OSTREE_REPO_COMMIT_STATE_PARTIAL) > 0 &&
+                  g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
+                {
+                  g_clear_error (&local_error);
+                }
+              else
+                {
+                  g_propagate_error (error, local_error);
+                  goto out;
+                }
+            }
         }
     }